In [1]:
#!python
# @NotebookService nb


Out[1]:
No Outputs

Using nb.display(), the kernel will choose automatically the better output format possible according to the type of data.


In [2]:
nb.display(range(10))


Out[2]:
0
1
2
3
4
5
6
7
8
9

In [3]:
nb.display(dict(name="Adam", color="blue"))


Out[3]:
KeyValue
colorblue
nameAdam

In [7]:
table = [{"x": 0, "y": 0},
         {"x": 1, "y": 10},
         {"x": 2, "y": 20},
         {"x": 3, "y": 30},
         {"x": 4, "y": 40},
         {"x": 5, "y": 50},
         {"x": 6, "y": 60}]


Out[7]:
No Outputs

In [8]:
nb.table(table)


Out[8]:
xy
00
110
220
330
440
550
660

Helper methods allow you to force the type of output you want.


In [9]:
nb.markdown("**This is bold** and *this is italic*")


Out[9]:

This is bold and this is italic


In [10]:
nb.latex("$$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$$")


Out[10]:
$$\sum_{i=0}^n i^2 = rac{(n^2+n)(2n+1)}{6}$$

In [12]:
html_code = """
<html>
<head>
<style>
table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even) {
    background-color: #dddddd;
}
</style>
</head>
<body>

<table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>Ernst Handel</td>
    <td>Roland Mendel</td>
    <td>Austria</td>
  </tr>
</table>

</body>
</html>"""


Out[12]:
No Outputs

In [13]:
nb.html(html_code)


Out[13]:
Company Contact Country
Alfreds Futterkiste Maria Anders Germany
Centro comercial Moctezuma Francisco Chang Mexico
Ernst Handel Roland Mendel Austria